<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>河套灌区农业面源污染决策支持系统</title>
    <style>
        /* 全局样式 */
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 0;
            min-height: 100vh; /* 确保body至少和视口一样高 */
            position: relative; /* 为背景图片容器定位 */
            overflow: hidden; /* 防止滚动条出现 */
        }

        /* 背景图片容器 */
        .bg-container {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: -1; /* 确保背景在内容下方 */
        }

        /* 背景图片网格布局 */
        .bg-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            grid-template-rows: 1fr 1fr;
            width: 100%;
            height: 100%;
        }

        /* 每个背景图片单元格 */
        .bg-cell {
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
        }

        /* 标题容器 - 水平居中 */
        .header-container {
            width: 100%;
            text-align: center;
            padding: 20px 0;
        }

        /* 标题样式 */
        h1, h2 {
            color:rgb(224, 249, 126);
            margin: 0;
            padding: 5px 0;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); /* 添加文字阴影提高可读性 */
        }
        h1 { font-size: 70px; }
        h2 { font-size: 70px; }

        /* 登录容器 - 水平居中 */
        .login-wrapper {
            width: 100%;
            display: flex;
            justify-content: center;
            padding: 20px 0;
        }

        /* 登录表单样式 */
        .login-container {
            background: rgba(255, 255, 255, 0.9); /* 半透明背景 */
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 0 15px rgba(0,0,0,0.2);
            width: 300px;
            text-align: center;
        }
        h4 {
            color: #333;
            margin-bottom: 1.5rem;
            font-size: 30px;
        }
        input {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            width: 100%;
            padding: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #45a049;
        }
        .message {
            margin-top: 1rem;
            color: #d32f2f;
        }
        .register-link {
            margin-top: 1rem;
            display: block;
            color: #666;
            text-decoration: none;
            transition: color 0.3s;
        }
        .register-link:hover {
            color: #333;
        }
    </style>
</head>
<body>
    <!-- 背景图片容器 -->
    <div class="bg-container">
        <div class="bg-grid">
            <div class="bg-cell" style="background-image: url('C:/Users/10484/Desktop/网页开发/山体.jpg')"></div>
            <div class="bg-cell" style="background-image: url('C:/Users/10484/Desktop/网页开发/葵花.jpg')"></div>
            <div class="bg-cell" style="background-image: url('C:/Users/10484/Desktop/网页开发/牛群.jpg')"></div>
            <div class="bg-cell" style="background-image: url('C:/Users/10484/Desktop/网页开发/羊群.jpg')"></div>
        </div>
    </div>

    <!-- 标题部分 - 水平居中 -->
    <div class="header-container">
        <h1>欢迎来到</h1>
        <h2>河套灌区农业面源污染决策支持系统</h2>
    </div> 
    
    <!-- 登录表单 - 水平居中 -->
    <div class="login-wrapper">
        <div class="login-container">
            <h4>用户登录</h4>
            <form id="loginForm">
                <input type="text" id="username" placeholder="用户名" required>
                <input type="password" id="password" placeholder="密码" required>
                <button type="submit">登录</button>
            </form>
            <div id="message" class="message"></div>
            <a href="#" id="registerBtn" class="register-link">没有账号？立即注册</a>
        </div>
    </div>

    <script>
    document.getElementById('loginForm').addEventListener('submit', async (e) => {
    e.preventDefault(); // 阻止表单默认提交行为
    const username = document.getElementById('username').value;
    const password = document.getElementById('password').value;
    
    try {
        const response = await fetch('http://localhost:3030/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ username, password })
        });
        
        const data = await response.json();
        if (data.success) {
            window.location.href = '首页.html';
        } else {
            document.getElementById('message').textContent = data.message;
        }
    } catch (error) {
        document.getElementById('message').textContent = "网络错误: " + error.message;
    }
});
  </script>
</body>
</html>